home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / sound / players / naudio.lzh / naudio / examples / m_player.c < prev    next >
C/C++ Source or Header  |  1993-11-23  |  7KB  |  196 lines

  1. /* ----------------------------------------------------------
  2.    Hello,
  3.       this is a little demo program to show you how to
  4.       play ProTracker modules with the NAUDIO library.
  5.       This is a little .TTP program that plays the file
  6.       given on the command line.
  7.  
  8.       You can find a demo module in NAUDIO\MODULES.
  9.                                            ("we are wicked")
  10.    --------------------------------------------------------- */
  11. #include <naudio\naudio.h>          /* always need this file */
  12. #include <tos.h>                    /* for Bconin            */
  13. #include <errno.h>
  14. #include <stdio.h>                  /* for fprintf et.al.    */
  15. #include <ctype.h>                  /* for toupper           */
  16. #include <stdlib.h>
  17.  
  18. #define DO_DISPLAY   1
  19. #define FRQ 11000
  20.  
  21. static lword   rfrq     = FRQ;      /* some default values  */
  22. static word    brk_jump = 1;
  23. static word    pal      = 1;
  24. static word    type     = PSG_ENGINE;    /* default ENGINE! */
  25. static word    s_loop;
  26.  
  27. /* ----------------------------------------------------------
  28.    If you want you can set DO_DISPLAY to 1 and see a little
  29.    trace of the module, as its being played.
  30.    ---------------------------------------------------------- */
  31. void  display( n_module *song)
  32. {
  33. #if DO_DISPLAY
  34.    static   oeseqno = -1,
  35.             oepc;
  36.  
  37.    /* if current 'effective' sequence number is different or
  38.       if the tracker has moved down to another entry in the
  39.       pattern, then output something.
  40.     */
  41.    if( ntrack->eseqno != oeseqno || ntrack->epc != oepc)
  42.    {
  43.       oeseqno  = ntrack->eseqno;
  44.       oepc = ntrack->epc;
  45.       printf( "%01X: Position #%d  Pattern #%d Entry #%02X\n",
  46.                   ntrack->on_voices, oeseqno, song->sequence[ oeseqno],
  47.                   oepc);
  48.    }
  49. #endif
  50. }
  51.  
  52.  
  53. /* ----------------------------------------------------------
  54.                      Here's where it's at
  55.    ---------------------------------------------------------- */
  56. main( argc, argv)
  57. char  *argv[];
  58. {
  59.    int   i = 0;
  60.    char  *modfile = 0;
  61.    lword foo;
  62.  
  63.    if( argc == 1)
  64.       goto usage;
  65.  
  66.    naudio_init();             /* initialize library         */
  67.    naudio_all();              /* allow all output devices   */
  68.  
  69.    while( ++i < argc)         /* now parse command line     */
  70.    {
  71.       if( *argv[i] == '-')
  72.          switch( tolower( argv[i][1]))
  73.          {
  74.             case 'f' :
  75.                if( ++i >= argc)
  76.                   goto usage;
  77.                foo = atol( argv[ i]);
  78.                if( foo)
  79.                   rfrq = foo;
  80.                else
  81.                   goto usage;
  82.                break;
  83.  
  84.             case 'c' :
  85.                ntrack->cia = ! ntrack->cia;        /* set CIA compatibility   */
  86.                break;                           /* or not ...              */
  87.  
  88.             case 'p' :
  89.                pal = ! pal;                     /* set PAL/NTSC flag for   */
  90.                break;                           /* enhanced Amiga comp.    */
  91.  
  92.             case 'l' :
  93.                s_loop = ! s_loop;               /* allow looping ?         */
  94.                break;
  95.  
  96.             case 'd' :                          /* get output device       */
  97.                if( ++i >= argc)
  98.                   goto usage;
  99.                type = (int) atol( argv[ i]);
  100.                break;
  101.  
  102.             case 'j' :
  103.                brk_jump = ! brk_jump;           /* allow looping of module ? */
  104.                break;
  105.  
  106.             default  :
  107.                goto usage;
  108.          }
  109.       else
  110.          if( modfile)
  111.             goto usage;
  112.          else
  113.             modfile = argv[ i];
  114.    }
  115.  
  116.    if( modfile)                              /* got something to do ?     */
  117.    {
  118.       n_module *song;                        /* yes, want to play a song! */
  119.  
  120.          /* init engine, with desired frequency, output device and PAL flag
  121.             to play modules.
  122.           */
  123.       if( ! (rfrq = ntrack_engine( rfrq, type, pal)))
  124.          return( 1);
  125.  
  126. #if DO_DISPLAY
  127.       fprintf( stderr, "Actual replay frequency: %ldHz\n", rfrq);
  128. #endif
  129.                                               /* load in PT module from file */
  130.       if( song = nmodule_load( modfile))
  131.       {
  132.                                     /* set module to play from the beginning */
  133.          nmodule_play( song, 0, 0, 0, s_loop | (brk_jump << 1));
  134.  
  135.          if( naudio_start( 0))                     /* PLAY IT! */
  136.          {
  137.             fprintf( stderr, "Sound system locked\n");
  138.             goto fail;
  139.          }
  140.  
  141. loop:
  142.          do
  143.             display( song);                        /* print somethin' */
  144.          while( ! Bconstat( 2) && ntrack->song);      /* now wait for keypress
  145.                                                       or end of song */
  146.  
  147.          if( ntrack->song)                         /* mmm, still running ? */
  148.             switch( (int) ((Bconin( 2) & 0xFF)))
  149.             {
  150.                case ' ' :
  151.                case 'q' :
  152.                case 'Q' :                          /* Q so quit */
  153.                   break;
  154.  
  155.                case '1' :
  156.                   ntrack->on_voices ^= 0x1;        /* toggle voice 1-4 */
  157.                default  :
  158.                   goto loop;
  159.  
  160.                case '2' :
  161.                   ntrack->on_voices ^= 0x2;
  162.                   goto loop;
  163.  
  164.                case '3' :
  165.                   ntrack->on_voices ^= 0x4;
  166.                   goto loop;
  167.  
  168.                case '4' :
  169.                   ntrack->on_voices ^= 0x8;
  170.                   goto loop;
  171.             }
  172.          ntrack_stop();                         /* turn off sound    */
  173.          nmodule_free( song);                   /* get rid of module */
  174. fail:
  175.          naudio_done();                         /* destroy engine    */
  176.          return( 0);                            /* and say goodbye   */
  177.       }
  178.       fprintf( stderr, "Couldn't load \"%s\"\n", modfile);
  179.       naudio_done();
  180.       return( 1);
  181.    }
  182. usage:
  183.    fprintf( stderr,
  184. "Usage: m_player [flags] <modfile>\n\
  185. \t-f <replayfrequency> from 2048Hz to <= 60000Hz (def: %dHz)\n\
  186. \t-c do not use CIA timing\n\
  187. \t-p use NTSC timing (def: PAL)\n\
  188. \t-d <n>, 0: slow PSG,   1: fast PSG    2:PP (StarSampler)\n\
  189. \t        3: fast STE    4: good STE\n\
  190. \t        7: fast FALCON 8: good FALCON 9:fastest FALCON(!)\n\
  191. \t-l loop module (def: no)\n\
  192. \t-j break looping position jumps (def: yes)", FRQ);
  193.    return( 1);
  194. }
  195.  
  196.